/*
 * Pinhead.java
 *
 * Copyright (C) 2012 Matt Falkoski
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.falko.android.pinhead;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.MotionEvent;

/**
 * @author matt
 * 
 */
public class Pinhead extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.main);
		GLView_ = (GLSurfaceView) findViewById(R.id.glsurfaceview);
		GLView_.setEGLConfigChooser(false); // 16 bit, no z-buffer
		GLView_.setKeepScreenOn(true);
		DisplayMetrics dm = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dm);

		int width = dm.widthPixels;
		int height = dm.heightPixels;
		if (height > width) {
			width = dm.heightPixels;
			height = dm.widthPixels;
		}

		// Check if the system supports OpenGL ES 2.0.
//		final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
//		final ConfigurationInfo configurationInfo = activityManager
//				.getDeviceConfigurationInfo();
//		final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;
//
		GameRenderer renderer;
//		if (supportsEs2) {
//
//			
//		} else {
//			// This is where you could create an OpenGL ES 1.x compatible
//			// renderer if you wanted to support both ES 1 and ES 2.
//			return;
//		}
		
		renderer = new GameRenderer(getBaseContext(), width, height);
		GLView_.setRenderer(renderer);
		GLView_.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	@Override
	protected void onPause() {
		super.onPause();
		GLView_.onPause();
	}

	@Override
	protected void onResume() {
		super.onResume();
		GLView_.onResume();
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		return false;
	}

	GLSurfaceView GLView_;
}
